// /rule/addRuleInfo.do
document.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '../rule/addRuleInfo.do';
///首页
var form;
var _pageNum = 1;
  $(function(){
	  var _type = getUrlParam("type");
	  console.log(_type)
	  if(_type === "add"){
		  getRuleListAdd();
	  }else if(_type === "edit"){
		  getRuleListAdd();
		  showEditData();
	  }else{
		  getRuleList();
	  }
  })
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getRuleList();
	  })
});
  function getRuleList(){
	  _ajax_get('../rule/getRuleList',{pageNum:_pageNum},function(res){
		  console.log(res);
		  if(!res.returnObject){
			  var html = '<div class="layui-form-mid layui-word-aux no-more-data">暂无更多数据</div>';
			  $(".layui-table ").after(html);
			  return;
		  }
		  showPageInfo(res.returnObject);
		  $(".x-right span").text(res.returnObject.total);
		  var html = "";
		  $.each(res.returnObject.list,function(i,v,arr){
			  html+=' <tr><td>'
//    	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
//    	             +' </td>                                                                                                                  '
//    	             +' <td>'
    	             +(i+1)+'</td>                                                                                                             '
    	             +' <td>'+v.title+'</td>                                                                                           '
    	             +' <td><i class="iconfont">'+v.icon+'</i></td>                                                                                                      '
    	             +' <td>'+formatNullData(v.url)+'</td>                                                                                                      '
    	             +' <td class="td-manage">                                                                                                 '
    	             +'   <a title="编辑"  onclick="x_admin_show(\'修改权限\',\'./rule-add.html?type=edit&id='+v.id+'\',455,500)" href="javascript:;">                       '
    	             +'     <i class="layui-icon">&#xe642;</i>                                                                                 '
    	             +'   </a> '
    	             +'   <a title="删除" onclick="member_del(this,\''+v.id+'\')" href="javascript:;">                                         '
    	             +'     <i class="iconfont icon-delete x-red"></i>                                                                                 '
    	             +'   </a>                                                                                                                 '
    	             +' </td> </tr>';
		  })
		  $(".layui-table tbody").html(html);
	  })
  }
      
  function getRuleListAdd(){
	  _ajax_get('../rule/getRuleList',{pageSize:100},function(res){
		  console.log(res);
		  var list =  res.returnObject;
		  var html = '<option value="">请选择</option>';
		  $.each(list.list,function(i,v,arr){
    		  if(list){
    			  if(v.pId==74 || !v.id){
    				  html+='<option value="'+v.id+'">'+v.title+'</option>';
    			  }
    		  }
		  })
		  $(".pIdsel").html(html);
		  console.log(form);
		  form.render();
		 //
	  })
  }
  function showEditData(){
	  _url_ = '../rule/updateRuleInfo.do';
	  var _id = getUrlParam("id");
	  $("#paramKey").val(_id);
	  console.log(_id);
	  _ajax_get('../rule/getRuleById',{id:_id},function(res){
		  console.log(res);
		  _showData = res.returnObject;
		  
		  console.log(_showData);
		  form.val("formAdd", _showData);
			form.render('input');
	     /* var t1=window.setInterval(showData, 200);
	      var ti_show_dd = 0;
			function showData(){
				ti_show_dd++;
		    	console.log(_showData);
				if (_showData) {
				    window.clearInterval(t1); 
					form.val("formAdd", _showData);
					form.render(); 
				}
				if(ti_show_dd>=40){
					window.clearInterval(t1); 
				}
			} */
	  });
  }    
 
  
  	
 
  /*用户-删除*/
  function member_del(obj,_id){
      layer.confirm('确认要删除吗？',function(index){
          //发异步删除数据
    	  _url_ = '../rule/updateRuleInfo.do';
    	  _ajax_post(_url_,{status:0,id:_id},function(res){
    	      	console.log(res);
    	      	if(res.resultCode == 1000){
    	      	  getRuleList();
    	      	  layer.msg('删除成功!',{icon:1,time:2000});
    	      	}else{
    	      		layer.msg('删除失败!',{icon:1,time:2000});
    	      	}
    	      });
      });
  }
      
  function updateRule(data){
	  //发异步，把数据提交给后台
      _ajax_post(_url_,data,function(res){
      	console.log(res);
      	if(res.resultCode == 1000){
      	  parent.getRuleList();
      	  parent.layer.msg('操作成功!',{icon:1,time:2000});
      	  x_admin_close();
          // 获得frame索引
      	}else{
      		layer.msg('操作失败!',{icon:1,time:2000});
      	}
      });
  }
      
      
      
      
      
      
      
//添加 和 修改窗口     